////
////  CheckNFCViewController.swift
////  AESOLAR_IOS
////
////  Created by Mr.Wang on 2019/10/17.
////  Copyright © 2019 Mr.Wang. All rights reserved.
////
//
//import UIKit
//import RxSwift
//import RxDataSources
//
//class CheckNFCViewController: BaseUIViewController {
//    
//    let nfcUnit = NFCUint()
//    var locationUnit: LocationUnit?
//    
//    override func viewDidLoad() {
//        super.viewDidLoad()
//        
//        self.navigationItem.title = "江苏新源".localized
//        
//        let imageView = UIImageView().config
//            .contentMode(.scaleToFill)
//            .addTo(self.view)
//            .makeConstraints { (make) in
//                make.left.top.right.equalToSuperview()
//                make.height.equalTo(SCREEN_WIDTH * 0.693)
//        }.view
//        
//        let tipLabel = UILabel().config
//            .text("请将手机背面贴近芯片标签".localized)
//            .textAlignment(.center)
//            .textColor(APPConfig.baseColor)
//            .numberOfLines(0)
//            .font(.systemFont(ofSize: 16, weight: .medium))
//            .addTo(view)
//            .makeConstraints { (make) in
//                make.centerX.equalToSuperview()
//                make.top.equalTo(imageView.snp.bottom)
//                make.width.equalTo(SCREEN_WIDTH * 0.9)
//        }.view
//        
//        let checkButton = UIButton().config
//            .cornerRadius(22)
//            .masksToBounds(true)
//            .backgroundImage(UIImage.imageWithColor(APPConfig.baseColor))
//            .title("快速查验".localized)
//            .titleColor(.white)
//            .addTarget(self, action: #selector(scan))
//            .addTo(view)
//            .makeConstraints { (make) in
//                make.centerX.equalToSuperview()
//                make.top.equalTo(tipLabel.snp.bottom).offset(40)
//                make.height.equalTo(44)
//                make.width.equalTo(180)
//        }.view
//        
//        UIButton().config
//            .cornerRadius(22)
//            .masksToBounds(true)
//            .borderColor(APPConfig.baseColor)
//            .borderWidth(0.9)
//            .backgroundImage(UIImage.imageWithColor(#colorLiteral(red: 0.992969811, green: 0.992969811, blue: 0.992969811, alpha: 1)))
//            .backgroundImage(UIImage.imageWithColor(#colorLiteral(red: 0.8573158979, green: 0.8573158979, blue: 0.8573158979, alpha: 1)), for: .highlighted)
//            .title("切换条码查验".localized)
//            .titleColor(APPConfig.baseColor)
//            .addTarget(self, action: #selector(change))
//            .addTo(view)
//            .makeConstraints { (make) in
//                make.centerX.equalToSuperview()
//                make.top.equalTo(checkButton.snp.bottom).offset(15)
//                make.height.equalTo(44)
//                make.width.equalTo(180)
//        }
//        
//        if let path = Bundle.main.path(forResource: "nfc.gif", ofType: nil),
//            let data = try? Data.init(contentsOf: URL.init(fileURLWithPath: path)) {
//            imageView.image = UIImage.sd_tz_animatedGIF(with: data)
//        }
//        
//        nfcUnit.nfcErrorClosure = { [weak self] error in
//            let alert = UIAlertController.init(title: "系统提示".localized, message: error, preferredStyle: .alert)
//            alert.addAction(UIAlertAction.init(title: "确定".localized, style: .cancel, handler: nil))
//            self?.present(alert, animated: true, completion: nil)
//        }
//        
//    }
//    
//    @objc func scan() {
//        locationUnit = LocationUnit()
//        locationUnit?.showLoading = true
//        locationUnit?.takeOnce = true
//        
//        locationUnit?.addressRefuseClosure = { [weak self] in
//            self?.nfcUnit.successClosure = { udid in
//                self?.checkNFC(udid)
//            }
//            self?.nfcUnit.beginScan()
//            
//            self?.locationUnit = nil
//        }
//        locationUnit?.addressUpdate = { [weak self] address in
//            let longitude = self?.locationUnit?.longitude
//            let latitude = self?.locationUnit?.latitude
//            self?.nfcUnit.successClosure = { udid in
//                self?.checkNFC(udid,
//                               longitude: longitude,
//                               latitude: latitude,
//                               address: address)
//            }
//            self?.nfcUnit.beginScan()
//            self?.locationUnit = nil
//        }
//        locationUnit?.settingClosure = { [weak self] in
//            self?.locationUnit = nil
//        }
//        locationUnit?.startLocation()
//    }
//    
//    func checkNFC(_ UDID: String, longitude: String? = nil, latitude: String? = nil, address: String? = nil) {
//        ApiManager.verify(UDID, longitude: longitude ?? "", latitude: latitude ?? "", address: address ?? "").request()
//            .filterCode200()
//            .dataModelMap(CheckModel.self)
//            .trackingLoading()
//            .subscribe(onNext: { [weak self] (result) in
//                if result.result.isSuccess {
//                    self?.navigationController?
//                        .pushViewController(SuccessViewController(result: result.psrInfo),
//                                            animated: true)
//                } else {
//                    self?.navigationController?
//                        .pushViewController(FailureViewController(psrCheckId: result.id), animated: true)
//                }
//            }).disposed(by: rx.disposeBag)
//    }
//    
//    @objc func change() {
//        let vc = CheckScanViewController()
//        self.navigationController?.pushTo(vc, remove: 1)
//    }
//    
//    override func navigationBarStyle() -> NavigationBarStyle {
//        return .baseColor
//    }
//    
//}
